/*
 * bitmap.c
 *
 *  Created on: 28/10/2011
 *      Author: Federico Croci
 */

#include "bitmap.h"

void bitmap_marcarBit(bitmap map,unsigned int posicion){
	unsigned int posEnVec=posicion/8;
	unsigned char nroBitEnByte =posicion%8;
	unsigned char bit=1;

	bit<<=(8-nroBitEnByte);//shift de bit hacia izquierda

	map[posEnVec]+=bit;
}
void bitmap_desmarcarBit(bitmap map, unsigned int posicion){
	unsigned int posEnVec=posicion/8;
	unsigned char nroBitEnByte =posicion%8;
	unsigned char bit=1;

	bit<<=(8-nroBitEnByte);//shift de bit hacia izquierda

	map[posEnVec]-=bit;
}
int bitmap_estaMarcado(bitmap map, unsigned int posicion){
	unsigned int posEnVec=posicion/8;
	unsigned char nroBitEnByte =posicion%8;
	unsigned char bit=1;

	bit<<=(8-nroBitEnByte);//shift de bit hacia izquierda

	if((bit^map[posEnVec])!=0){  // ^ es XOR
		return 1;
	}
	else {
		return 0;
	}
}
